package com.study.lihan.letcode;

import com.study.lihan.letcode.util.Util;

/*
*https://leetcode-cn.com/problems/remove-element/
* */
public class My27 {
    public static void main(String[] args) {
     int[] nums = {0,1,2,2,3,0,4,2};
     int val =2;
     Solution27 solution27 = new Solution27();
     int result = solution27.myremoveElement(nums,val);
        System.out.println("结果是："+result);
        Util.printArr(nums);
    }
}


class Solution27 {

    public int myremoveElement(int[] nums, int val) {
        if(nums == null || nums.length == 0) return  0;
        int len = nums.length;
        int count =0;
        for(int firstIndex = 0,lastIndex = len-1;firstIndex<=lastIndex;){
            if(nums[firstIndex] != val){
                firstIndex++;
                count++;
                continue;
            }
            if(nums[lastIndex] != val){
                nums[firstIndex] = nums[lastIndex];
                nums[lastIndex] =0;
                firstIndex++;
                lastIndex--;
                count++;
                continue;
            }
            nums[lastIndex] = 0;
            lastIndex--;

        }
        return  count;
    }
    public int removeElement(int[] nums, int val) {
      return  0;
    }
}